<template>
	<view class="m-page">
		<view class="cu-form-group">
			<input placeholder="请输入标题" name="input" v-model="title"></input>
		</view>
		<view class="cu-form-group m-content">
			<textarea class="textarea" maxlength="-1" :disabled="modalName!=null" v-model="content" placeholder="请输入内容"></textarea>
		</view>
		<view class="cu-bar bg-white tabbar border m-footer">
			<view :class="['action', is_password? 'text-blue' : 'text-gray']" @click="passwordAction">
				<view class="cuIcon-lock"></view>加密
			</view>
			<view :class="['action', is_top? 'text-blue' : 'text-gray']" @click="topAction">
				<view class="cuIcon-top"></view>置顶
			</view>
			<view class="bg-red submit" @click="saveWord">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: "",
				content: "",
				is_top: false,
				is_password: false,
				modalName: null
			}
		},
		methods: {
			saveWord() {
				const that = this
				uni.request({
					// url:'http://47.94.164.187:9001/api/content/save/',
					url: 'http://127.0.0.1:9001/api/content/save/',
					method: 'POST',
					data: {
						title: that.title,
						content: that.content,
						isTop: that.is_top ? 1 : 0,
						isPassword: that.is_password ? 1 : 0
					},
					header: {
						token: uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						if (res.data.code === 200) {
							uni.showToast({
								title: '成功',
								success: (res) => {
									uni.redirectTo({
										url:'/pages/home/index'
									})
								}
							})
						}
						
						if (res.data.code === 405) {
							uni.showToast({
								title: res.data.msg,
								image:"/static/error.png"
							})
						}
					}
				})
			},
			topAction() {
				// console.log(123)
				this.is_top = !this.is_top
				if(!this.is_top){
					uni.showToast({
						title: '取消',
					})
				}else{
					uni.showToast({
						title: '置顶成功',
					})
				}
			},
			passwordAction() {
				// console.log(123)
				this.is_password = !this.is_password
				if(!this.is_password){
					uni.showToast({
						title: '取消',
					})
				}else{
					uni.showToast({
						title: '加密成功',
					})
				}
			}
		},
		computed: {

		}
	}
</script>

<style lang="scss" scoped>
	.m-page {
		background-color: #fff;
		min-height: 100vh;
		display: flex;
		flex-direction: column;

		.m-content {
			flex: 1;
			display: flex;
			flex-direction: column;

			.textarea {
				flex: 1;
				// width: 100%;
				// height: 100%;
			}
		}

		.m-footer {
			// position: fixed;
			// bottom: 0;
			// width: 100%;
		}
	}
</style>
